package com.arron.simplefactory.pizzastore.improve;


import com.arron.simplefactory.pizzastore.CheesePizza;
import com.arron.simplefactory.pizzastore.GreekPizza;
import com.arron.simplefactory.pizzastore.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OrderPizza1 {
    SimpleFactory simpleFactory;
    public OrderPizza1(SimpleFactory simpleFactory) {
        this.simpleFactory = simpleFactory;
        setFactory();
    }

    public void setFactory(){
        Pizza pizza;
        String orderType;
        do {
            orderType = getType();
            pizza = this.simpleFactory.createPizza(orderType);

            if(pizza!=null) {
                pizza.setName(orderType);
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购失败。");
            }

        } while (true);
    }

    private String getType() {
        try {
            BufferedReader strIn = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strIn.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
